class ComponentDefinition:
    Legend = 0
    ValueTitle = 1
    ChartTitle = 2
    CategoryTitle = 3
    # 数据元素绘图区域 plot_area
    Canvas = 5


def combine_cls_predict(yolocls_results, cornercls_results, cached_pred_results):
    combine_results = dict()

    for filename in yolocls_results.keys():
        yolocls_result = yolocls_results[filename]
        cornercls_result = cornercls_results[filename]
        cached_data = cached_pred_results[filename]
        yolocls_data = yolocls_result["data"]
        cornercls_data = cornercls_result["data"]
        # 筛选出cached_pred_results的title，x_title以及y_title
        # title = cached_data["chart_title"]
        # category_title = cached_data["x_title"]
        # value_title = cached_data["y_title"]

        chart_type = yolocls_data[0]
        corner_cls_info = cornercls_data[1]
        yolo_cls_info = yolocls_data[1]

        combine_result = dict()

        combine_result["data_type"] = chart_type

        if "5" in yolo_cls_info.keys():
            combine_result[ComponentDefinition.Canvas - 1 + chart_type] = yolo_cls_info["5"]
        else:
            if "5" in corner_cls_info.keys():
                combine_result[ComponentDefinition.Canvas - 1 + chart_type] = corner_cls_info["5"]

        # 将corner net的其他检测结果写入
        for key in corner_cls_info.keys():
            if int(key) < 4:
                combine_result[int(key)] = corner_cls_info[key]

        # yolo检测器其他公共元素的检测结果作为补充
        extra_component_detected_by_yolo = [key for key in yolo_cls_info.keys() if
                                            int(key) < 4 and key not in corner_cls_info.keys()]
        for key in extra_component_detected_by_yolo:
            combine_result[int(key)] = yolo_cls_info[key]

        # 判断combine_result中是否存在各类title
        # if 1 not in combine_result.keys() and len(value_title) != 0:
        #     combine_result[1] = value_title[0][0]
        #
        # if 2 not in combine_result.keys() and len(title) != 0:
        #     combine_result[1] = title[0][0]
        #
        # if 3 not in combine_result.keys() and len(category_title) != 0:
        #     combine_result[1] = category_title[0][0]

        combine_results[filename] = combine_result

    return combine_results
        